// stores/bpmn.ts
import { defineStore } from 'pinia';
import type CommandStack from 'diagram-js/lib/command/CommandStack';
import { message } from 'ant-design-vue';
import {getIncomingTree} from '@/utils/common'

export const useBpmnStore = defineStore('bpmn', {
  state: () => ({
    commandStack: null as CommandStack | null,
  }),
  actions: {
    setCommandStack(commandStack: CommandStack) {
      this.commandStack = commandStack;
    },
    undo(elementId) {
      if (this.commandStack?.canUndo()) {
        const result =  getIncomingTree(elementId);
        if(result==null)
            return;
        if(result.incoming.length>0){
            for(const res of result.incoming){
                if(res.type==="bpmn:UserTask"&&res.outgoing.length>1){
                    message.error("设计不合理")
                    this.commandStack.undo();
                }
            }
        }
        console.log(result,"result2222222222222")
        
      }
    },
  },
});